<template>
  <div class="order_details">
    <div class="commons_top">
      <div class="commons_back" @click="$router.go(-1)">
        <img src="@/assets/index/back.png" />
      </div>
      <span class="commons_title">订单详情</span>
    </div>
    <div class="order_info">
      <div class="order_con" v-if="pageData.infoList&&pageData.infoList.length>0">
        <div class="order_box">
          <div class="order_status">{{pageData.statusZh}}</div>
        </div>
        <div class="order_top" v-for="item in pageData.infoList" :key="item.index">
          <img class='order_cover' src="@/assets/my/cover.png" v-if="listQuery.orderType == 1">
          <img class='order_cover' :src="coverUrl(item.cover)"
          @error="errImg(item.type==1?'book':item.type==4?'video':'audio')" v-else >
          <div class="order_det">
            <div class="order_name">{{item.name}}</div>
            <div class="order_total">小计：<span>￥{{pageData.payment}}</span></div>
            <div class="order_bot" @click="payBtn(pageData.payment,pageData.id)" v-if="pageData.status!=6&&pageData.status!=-1">去付款</div>
          </div>
        </div>
      </div>
    </div>
    <div class="order_main">
      <div class="order_list">
        <p class='text'>订单编号：{{pageData.code}}</p>
        <p class='text'>下单时间：{{pageData.uploadTime}}</p>
      </div>
      <div class="order_list" style="border:none">
        <p class='text' v-if="pageData.status==6">支付方式：{{pageData.payTypeZh}}</p>
      </div>
    </div>
    <!-- 支付弹窗 -->
    <pay-item :dialog="payDialog" @setDialog='setDialog' :currentPrice="currentPrice" :currentId="currentId" @getDet="getDet" :payType="payType"></pay-item>
  </div>
</template>

<script>
import '@static/css/common.css'
import { Toast } from 'mint-ui';
import { orderDetAPI } from '@/api/order.js'
import pay from '@/components/pay'

export default {
  name:'orderDet',
  components: { payItem: pay },
  data() {
    return {
      pageData:{},
      invoiceText: ['未开票', '开票完成', '已申请'],
      listQuery:{
        id:'',
        orderType:''
      },
      discount: null, //优惠价钱
      payDialog: false,
      currentPrice: null,
      currentId: null,
      payType: true
    }
  },
  mounted() {
    this.listQuery.id = this.$route.query.id
    this.listQuery.orderType = this.$route.query.orderType
    this.getDetails()
  },
  methods: {
    payBtn(price,id) {
      this.currentPrice = price
      this.currentId = id
      this.payDialog = true
    },
    setDialog(val) {
      this.payDialog = val
    },
    getDet() {
      this.getDetails()
    },
    getDetails() {
      orderDetAPI(this.listQuery.id).then(res =>{
        if (res.data.code == 0) {
          this.pageData = res.data.data
          let price = this.pageData.payment - this.pageData.orderPayment
          // this.discount = price.toFixed(2)
        } else{
          Toast(res.data.msg);
        } 
      })
    },
  }
}
</script>


<style scoped>
.order_details{
  overflow: hidden;
  background: #F8F8F8;
  min-height: 100vh;
}
.commons_top {
  background: #fff;
}
/* 订单信息 */
.order_info{
  padding: 0.1rem 0 0.2rem;
  box-sizing: border-box;
}
.order_con {
  background: #fff;
  box-shadow:0px 2px 40px 0px rgba(127,127,127,0.04);
  padding: 0.4rem 0.45rem 0.3rem;
}
.order_box {
  overflow: hidden;
}
.order_status {
  float: right;
  color: #999999;
  font-size: 11px;
}
.order_top{
  padding-top: 0.43rem;
  overflow: hidden;
  display: flex;
}
.order_cover{
  width: 1.1rem;
  height: 1.51rem;
  margin-right: 0.3rem;
  border-radius: 0.09rem;
}
.order_det {
  flex: 1;
}
.order_name{
  color: #202021;
  font-weight:bold;
  font-size: 15px;
}
.order_total{
  color: #333333;
  font-weight:500;
  line-height:0.4rem;
  margin-top: 0.97rem;
  font-size: 15px;
  float: right;
}
.order_total span{
  color: #FE2023;
  font-size: 17px;
}
.order_bot {
  clear: both;
  float: right;
  width: 1.31rem;
  height: 0.6rem;
  margin-top: 0.44rem;
  background: #FFFFFF;
  border: 1px solid #FF7168;
  border-radius: 0.09rem;
  text-align: center;
  line-height: 0.6rem;
  color: #FF7168;
  font-size: 13px;
}
/* 订单编号 */
.order_main{
  background: #fff;
  font-size: 12px;
}
.order_list{
  color:#333333;
  padding: 0 0.3rem;
  box-sizing: border-box;
  border-bottom: 1px solid #eeeeee;
}
.order_list:first-child {
  padding-top: 0.33rem;
  padding-bottom: 0.34rem;
  box-sizing: border-box;
}
.order_list:first-child .text {
  line-height: 0.48rem;
  color: #999999;
}
.order_list:last-child .text{
  line-height: 0.8rem;
  color: #333333;
}
.order_list .text{
  margin: 0;
  padding: 0;
  font-size: 13px;
}
</style>
